home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / os2 / srefv12i.zip / srefmon.cmd < prev    next >
OS/2 REXX Batch file  |  1997-04-19  |  45KB  |  1,537 lines

  1. /*SRE_Filter monitor routine (run as a non-transient thread in same process
  2. as goserve */
  3.  
  4. /* ---------- DO NOT CHANGE BELOW HERE  ----------------*/
  5.  
  6. if \RxFuncQuery("SockLoadFuncs") then nop
  7. else do
  8.        call RxFuncAdd "SockLoadFuncs","rxSock","SockLoadFuncs"
  9.        call SockLoadFuncs
  10. end
  11. foo=rxfuncquery('UZLoadFuncs')   /* load UNZIP dll */
  12. if foo=1 then do
  13.   call RxFuncAdd 'UZLoadFuncs', 'UNZIPAPI', 'UZLoadFuncs'
  14.   call UZLoadFuncs
  15. end
  16.  
  17. foo=rxfuncquery('UZLoadFuncs')   /* load UNZIP dll */
  18. if foo=1  then call pmprintf(' Warning: UNZIPAPI.DLL not found ')
  19.  
  20. parse arg goserve_pid, thesem,servdir,SERVERPORT,envadd,max_semwait,moreargs
  21. if servdir=" " then do
  22.    say " This SRE-Filter daemon is NOT meant to be invoked from an OS/2 prompt!"
  23.   exit
  24. end  /* Do */
  25.  
  26.  
  27. signal on error name yipes ; signal on syntax name yipes ;
  28.  
  29.  
  30. parse var moreargs loadthreshold ',' backupserverlist ','  ,
  31.      delay_seconds ',' message_scramble ',' record_cache_lines ',' logon_limit ',' ssi_extensions ',' ,
  32.      ssi_cache_size ',' ssi_cache_duration ',' ssi_cache_stamp ',' save_state ',' no_no_record
  33. loadthreshold=strip(loadthreshold) ; backupserverlist=strip(backupserverlist)
  34. delay_seconds=strip(delay_seconds) ; message_scramble=strip(message_scramble)
  35. record_cache_lines=strip(record_cache_lines)
  36. logon_limit=strip(logon_limit)
  37. ssi_extensions=strip(ssi_extensions)
  38. ssi_cache_size=strip(ssi_cache_size)
  39. ssi_cache_duration=strip(ssi_cache_duration)
  40. ssi_cache_stamp=upper(strip(ssi_cache_stamp))
  41. save_state=strip(save_state)
  42. no_no_record=strip(no_no_record)
  43.  
  44. if datatype(logon_limit)<>'NUM' then logon_limit=0
  45. if datatype(delay_seconds)<>'NUM' then delay_Seconds=9
  46. if datatype(message_scramble)<>'NUM' then message_scramble=12415
  47.  
  48. /*if goserve_pid=" " | goserve_pid="?" | envadd="" then do
  49.    say " This is used by SRE-Filter to manage ancillary threads. "
  50.    say " It is not meant to be run as a standalone program! "
  51.    exit
  52. end
  53. */
  54.  
  55. if max_semwait="" then max_semwait=3000
  56. CALL  load_rxl(0)  /* load macrospace library */
  57. IF result<0  then    do       /* fatal error if not found */
  58.   call pmprintf(' SRE-Filter monitor: ERROR: could not load macrospace library ')
  59.   EXIT
  60. end
  61.  
  62. doo=dostid()
  63. oo=dospid()||' '||dostid()
  64.  
  65. activecache.0=0
  66.  
  67. numeric digits 11
  68.  
  69. call pmprintf(" SRE-Filter Monitor: Initializing on port "|| serverport || ": " || filter_name)
  70. call pmprintf(" SRE-Filter monitor: Goserve pid ="|| goserve_pid' , monitor thread '||doo)
  71. call pmprintf(" SRE-Filter monitor: Using semaphore "|| thesem)
  72. parse upper version rexxtype .
  73. call pmprintf("SRE-Filter monitor: Using REXX version: " rexxtype)
  74.  
  75. if record_cache_lines>0 then
  76.    call pmprintf(" SRE-Filter monitor: Record cache file size= "||record_cache_lines)
  77.  
  78. init_file=servdir||"\INITFILT."||serverport
  79. filedate.initfilt=file_juldate(init_file)
  80. call get_initfilt(0)
  81.  
  82. call clear_temp(0)
  83.  
  84.  
  85. if result<0  then do
  86.   call pmprintf(" SRE-Filter fatal error : No INITFILT file ")
  87.   exit
  88. end
  89.  
  90. filedate.repstrgs=file_juldate(repstrgs_file)
  91. repsvars.0=0
  92.  
  93. call chk_repstrgs(0)
  94.  
  95. filedate.access=file_juldate(access_file)
  96. aa=start_access(0)
  97. filedate.alias=file_juldate(alias_file)
  98. aa=start_alias(0)
  99. filedate.user=file_juldate(user_file)
  100. aa=start_user(0)
  101. filedate.virtual=file_juldate(virtual_file)
  102. aa=start_virtual(0)
  103. aa=start_ssicache(0)
  104.  
  105. aa=start_postf(0)
  106. aa=eventsem_create(thesem)
  107. if aa<0 then do
  108.  call pmprintf(" SRE-Filter monitor: ERROR: could not create semaphore: "||thesem)
  109.  exit
  110. end
  111. foo=eventsem_post(thesem)       /* let the boys have it */
  112.  
  113. call pmprintf(' SRE-Filter Monitor: Begin monitoring parameters files ..... ')
  114. nloops=0
  115. geelist="INITFILT REPSTRGS ALIAS ACCESS USER VIRTUAL "
  116. do forever
  117.   nloops=nloops+1
  118.  
  119.    CALL load_rxl(1)
  120.    IF result<0 then do
  121.       call pmprintf(' leaving after rxl error')
  122.       leave
  123.    end
  124.  
  125. /* get dates of current files  -- 0 if doesnt exist */
  126.    t1.initfilt=file_juldate(init_file)
  127.    t1.repstrgs=file_juldate(repstrgs_file)
  128.    t1.alias=file_juldate(alias_file)
  129.    t1.access=file_juldate(access_file)
  130.    t1.user=file_juldate(user_file)
  131.    t1.virtual=file_juldate(virtual_file)
  132.  
  133. /* any of them newer then last stored files */
  134.    redo=0
  135.    do mm=1 to words(geelist)
  136.        oo1=word(geelist,mm)
  137.        if t1.oo1 > filedate.oo1 then do
  138.            redo=1
  139.            filedate.oo1=t1.oo1
  140.         end
  141.    end
  142.  
  143.    if nloops>150 then do         /* every 30 minutes, reset it */
  144.         nloops=1                  /* just to be safe! */
  145.         redo=1
  146.    end
  147.    foo=value('SREF_REDO',,'os2environment')
  148.    if foo=1 then redo=1
  149.    foo=value('SREF_REDO',0,'os2environment')  /* reset to 0*/
  150.  
  151. /* one of three ways of being a redo? then reset */
  152.    if redo=1 then do            /* reset all stuff */
  153.  
  154.       call pmprintf(" SRE-Filter resetting variables ")
  155.  
  156.  
  157.       call get_initfilt(filedate.initfilt)
  158.       if result<0 then do
  159.           call pmprintf(' leaving after initfilt error ')
  160.           leave
  161.       end
  162.       call start_access(1)
  163.       call start_alias(1)
  164.       call start_user(1)
  165.  
  166.       call start_virtual(1)
  167.       call chk_repstrgs(0)
  168.  
  169.  
  170. /* store dates of just reset files (initfilt may have changed names */
  171.      filedate.access=file_juldate(access_file)
  172.      filedate.alias=file_juldate(alias_file)
  173.      filedate.user=file_juldate(user_file)
  174.      filedate.virtual=file_juldate(virtual_file)
  175.      filedate.repstrgs=file_juldate(repstrgs_file)
  176.      filedate.initfilt=file_juldate(init_file)
  177.      CALL PMPRINTF(' SRE-Filter Monitor: Success resetting parameters ')
  178.     end
  179.  
  180. /* always check up on cached files (note that they may have
  181. changed if initfilt was updated */
  182.  
  183.     n=delay(delay_seconds)
  184.  
  185. /* get current env variables, perhaps write to pmprintf */
  186.    if display_env=1 then do
  187.         a=rxqueue('s','session')
  188.        call pmprintf(" Current SREF environment variables -----  ")
  189.         do queued(); pull .; end                   /* flush */
  190.         address cmd '@set | rxqueue'     /* execute the command */
  191.         do queued()
  192.            parse pull ares
  193.            iii=min(100,length(ares))
  194.            if abbrev(upper(ares),'SREF_')=1 then
  195.              call pmprintf(left(ares,iii))
  196.         end
  197.        call pmprintf(' --- end of sref environment variables ')
  198.        display_env=0
  199.    end
  200.  
  201. end  /* forever loop */
  202.  
  203.  
  204. exit
  205.  
  206. yipes:
  207. call pmprintf(" error at " sigl )
  208. exit 'Error in SREFMON'
  209.  
  210. /* --------- END OF MAIN ---------------------------------------- */
  211.  
  212. /* ------------------------------------------------- */
  213. /* Routine to check, and load if neccessary,  SREFILTR.RXL into macrospace */
  214. /* ------------------------------------------------- */
  215.  
  216. load_rxl:
  217. nosref0=1
  218. signal on syntax name nosref
  219. signal on error name nosref
  220.  
  221. filter_name=sref_version()   /* if not here, then skip to nosref */
  222. nosref0=0
  223. nosref:         /* if skipped here, then load .rxl */
  224. signal off syntax ; signal off error
  225.  
  226.  
  227. if nosref0=1  then do
  228.    first_load=1
  229.  
  230.    parse upper version rexxtype .
  231.    if rexxtype="OBJREXX" then do
  232.         call pmprintf(" SRE-Filter monitor: Loading SREFPRCO.RXL into macrospace ")
  233.         tt=servdir||'\SREFPRCO.RXL'
  234.    end
  235.    else do
  236.        call pmprintf(" SRE-Filter monitor: Loading SREFPRC1.RXL into macrospace ")
  237.        tt=servdir||'\SREFPRC1.RXL'
  238.    end
  239.    aa=macroload(tt)
  240.    if aa=0 then do
  241.       call pmprintf(" SRE-Filter Monitor: ERROR: "|| tt ||" not available! "|| aa)
  242.       RETURN -1
  243.    end
  244.    filter_name=sref_version()
  245.    CALL PMPRINTF(" SRE-Filter Monitor: Success on macrospace library load ")
  246. end
  247.  
  248. RETURN 1
  249.  
  250. /* ------------------------------------------------- */
  251. /* get date (fat and julian) of a file */
  252. /* ------------------------------------------------- */
  253.  
  254. file_juldate:procedure
  255.  
  256.  
  257. parse arg get_file , isquiet
  258. if GET_file=" " then return 0
  259.  
  260. eek=sysfiletree(translate(get_file,'\','/'),'gosh','FT')
  261. if gosh.0=0 then do  /* no file */
  262.    return 0
  263. end
  264. parse var gosh.1  atime .
  265. aa=sref_juldate('F',atime)
  266. return aa
  267.  
  268. /* ------------------------------------------------- */
  269. /* clear all $*.80 files out of tempdata_Dir */
  270. /* ------------------------------------------------- */
  271. clear_temp:
  272.  
  273. lookstar=tempdata_dir||'\$*.'||serverport
  274. foo=sysfiletree(lookstar,stuff,'FO')
  275. do mm=1 to stuff.0
  276.    foo=sysfiledelete(stuff.mm)
  277. end /* do */
  278. if stuff.0>0 then
  279.   call pmprintf('SRE-Filter monitor: Deleted ' stuff.0 ' old files from: 'tempdata_dir)
  280. lookstar=tempdata_dir||'\_DIRLIST.IDX'
  281. foo=sysfiledelete(lookstar)
  282.  
  283. lookstar=tempdata_dir||'\_*.DSH'         /* delete old directory cache files */
  284. foo=sysfiletree(lookstar,stuff,'FO')
  285. do mm=1 to stuff.0
  286.    foo=sysfiledelete(stuff.mm)
  287. end /* do */
  288. if stuff.0>0 then
  289.   call pmprintf('SRE-Filter monitor: Deleted ' stuff.0 ' old directory cache files from: 'tempdata_dir)
  290.  
  291. lookstar=tempdata_dir||'\_*.TMP'         /* delete old .TMP e files */
  292. foo=sysfiletree(lookstar,stuff,'FO')
  293. do mm=1 to stuff.0
  294.    foo=sysfiledelete(stuff.mm)
  295. end /* do */
  296. if stuff.0>0 then
  297.   call pmprintf('SRE-Filter monitor: Deleted ' stuff.0 ' _*.TMP files from: 'tempdata_dir)
  298. lookstar=strip(tempdata_dir||'\_T*.'||serverport)         /* delete old .TMP e files */
  299. foo=sysfiletree(lookstar,stuff,'FO')
  300. do mm=1 to stuff.0
  301.    foo=sysfiledelete(stuff.mm)
  302. end /* do */
  303. if stuff.0>0 then
  304.   call pmprintf('SRE-Filter monitor: Deleted ' stuff.0 ' _T*.'serverport ' files from: 'tempdata_dir)
  305.  
  306.  
  307.  
  308.  
  309.  
  310. return 0
  311.  
  312.  
  313.  
  314. /* ------------------------------------------------- */
  315. /* routine to load initfilt.nnn into macrospace
  316.    return 0= no change , 1= change,return<0=error */
  317. /* ------------------------------------------------- */
  318. get_initfilt:
  319.  
  320. get_file=init_file
  321. if get_file=" " then
  322.        return 0
  323. oy=stream(get_file,'c','query exists')
  324. if oy=0 then do
  325.    CALL PMPRINTF("SRE-Filter monitor: INITFILT file not found, "|| get_file)
  326.    return -1
  327. end
  328.  
  329. /* get list of possible host variables */
  330. a=rxqueue('s','session')
  331. do queued(); pull .; end                   /* flush */
  332. nhs=0
  333. address cmd '@set | rxqueue'     /* execute the command */
  334. do queued()
  335.   parse pull ares0
  336.   if abbrev(upper(ares0),'SREF_')=1 then do
  337.       parse upper var ares0 ares '=' .
  338.       ibeam=lastpos('.',ares)
  339.       if ibeam>0 then do
  340.            cat3=substr(ares,ibeam+1)
  341.            if datatype(cat3)<>'NUM' then do
  342.               parse var ares . '_' . '_' ares1 '=' .
  343.               interpret ares1||'=" " '
  344. /*              call pmprintf(' reset: ' ares1)*/
  345.            end          /* got a host entry */
  346.       end  /* got a . ed entry */
  347.    end     /* an sref entry */
  348. end     /* queued */
  349.  
  350.  
  351. call default_initfilt           /* default values */
  352.  
  353. ause=fileread(get_file,'filelines',,'E')
  354. If (ause=0) then  do               /*no such file,*/
  355.       CALL PMPRINTF("SRE-Filter monitor: INITFILT file unusable, "|| get_file)
  356.       return -1
  357. end
  358.  
  359. /*Allow for gratuitous coding calamity by clumsy users */
  360.  
  361. mm=0 ; nerrs=0
  362.  
  363. iat1: nop
  364.  
  365. /* exit here when entire file read. Before exiting, cleanup and save results */
  366.  
  367. if mm>=filelines.0 then do
  368.    signal off syntax
  369.    signal off error
  370.    signal off failure
  371.    if nerrs>0 then
  372.         return  -nerrs               /* any error is fatal */
  373.     call initfilt_checkup
  374.  
  375.     call save_envstuff
  376.  
  377. /* check on status of counter files (create if necessary ) */
  378.    res1=sref_init_counter(counter_file, upload_log , record_all_file , record_option)
  379.    parse var res1 counter_file  upload_log  record_all_file  record_option
  380.    call value envadd||'COUNTER_FILE',counter_file,'os2environment'
  381.    call value envadd||'UPLOAD_LOG',upload_log,'os2environment'
  382.    call value envadd||'RECORD_OPTION',record_option,'os2environment'
  383.    call value envadd||'RECORD_ALL_FILE',record_all_file,'os2environment'
  384.  
  385.    call value envadd||'SERVERPORT',serverport,'os2environment'
  386.  
  387.    call pmprintf(" SRE-Filter monitor: INITFILT file loaded, "||get_file)
  388.  
  389.    return 1
  390. end
  391.  
  392. mm=mm+1
  393. signal on syntax name foobar1
  394. signal on error name foobar1
  395. signal on  failure name foobar1
  396. filelines.mm=fix_me(filelines.mm)  /* convert from foo.host.n to foo.n.host */
  397. goo=strip(filelines.mm)
  398. if goo="" | left(goo,1)=";" then
  399.     signal iat1
  400.  
  401. /* convert PUBLIC_FILES to PUBLC_URLS */
  402. if abbrev(upper(goo),'PUBLIC_FILES')=1 then
  403.    goo='PUBLIC_URLS'||delstr(goo,1,12)
  404.  
  405. /* convert PUBLIC_URL. to PUBLC_URLS. */
  406. if abbrev(upper(goo),'PUBLIC_URL.')=1 then
  407.    goo='PUBLIC_URLS'||delstr(goo,1,10)
  408.  
  409.  ok=0
  410.  if abbrev(upper(goo),'SERVDIR')=1 then do
  411.      call pmprintf(' Warning: INITFILT not allowed to change SERVDIR variable ')
  412.      nop /* don't let it be changed! */
  413.  end
  414.  else
  415.     interpret goo
  416.  
  417.  ok=1
  418. foobar1:
  419. if ok=0 then do
  420.    nerrs=nerrs+1
  421.   call pmprintf(" SRE-Filter monitor: ERROR: in initfilt: "||goo)
  422. end
  423.  
  424.  
  425. signal iat1
  426.  
  427.  
  428. /* ---------------------------------------------- */
  429. /* Clean up parameters in initfilt */
  430. /* ---------------------------------------------- */
  431. initfilt_checkup:
  432.  
  433. checklog=STRIP(translate(checklog))
  434.   t1=wordpos(checklog,'NO YES ALWAYS INHOUSE')
  435.   if t1=0 then checklog='NO'
  436.  
  437. if auto_Name=0 then auto_name=" "
  438.    auto_name=translate(auto_name)
  439.  
  440.  
  441. /* include html for backward compataability */
  442. check_alias=is_true(check_alias,'Y YES 1 HTM HTML ')
  443.  
  444. accept_range=is_true(accept_range,'Y YES 1')
  445. no_include=is_true(no_include,'Y YES 1')
  446. no_interpret_code=is_true(no_interpret_code,'Y YES 1')
  447. no_processing=is_true(no_processing,'Y YES 1')
  448. use_stdout=is_true(use_stdout,'Y YES 1')
  449. do_send_piece=is_true(do_send_piece,'Y YES 1')
  450. add_user_name=is_true(add_user_name,'Y YES 1')
  451. add_resource_name=is_true(add_resource_name,'Y YES 1')
  452.  
  453. check_add_privs=is_true(check_add_privs,'Y YES 1')
  454.  
  455. if logon_fail_file=' '  then logon_fail_file=0
  456. if access_fail_file=' ' then access_fail_file=0
  457.  
  458. DEFAULT=STRIP(DEFAULT)
  459.    if default=' ' then default='INDEX.HTM'
  460.  
  461. /* check for existnce of varouse directories */
  462. mailbox_dir=translate(mailbox_dir,'\','/')
  463.    mailbox_dir=strip(mailbox_dir,'t','\')
  464. if dosisdir(mailbox_dir)=0 then do
  465.      call pmprintf(' SRE-Filter monitor: Warning, could not find mailbox_dir: 'mailbox_dir)
  466.      mailbox_dir=""
  467. end  /* Do */
  468.  
  469. messbox_dir=translate(messbox_dir,'\','/')
  470.    messbox_dir=strip(messbox_dir,'t','\')
  471. if dosisdir(messbox_dir)=0 then do
  472.      call pmprintf(' SRE-Filter monitor: Warning, could not find messbox_dir: 'messbox_dir)
  473.      messbox_dir=""
  474. end  /* Do */
  475.  
  476. config_dir=translate(config_dir,'\','/')
  477.    config_dir=strip(config_dir,'t','\')
  478. if dosisdir(config_dir)=0 then do
  479.      call pmprintf(' SRE-Filter monitor: Warning, could not find config_dir: 'config_dir)
  480.      config_dir=datadir()
  481. end  /* Do */
  482.  
  483.  
  484. workdata_dir=translate(workdata_dir,'\','/')
  485.    workdata_dir=strip(workdata_dir,'t','\')
  486. if dosisdir(workdata_dir)=0 then do
  487.      call pmprintf(' SRE-Filter monitor: Warning, could not find workdata_dir: 'workdata_dir)
  488.      workdata_dir=servdir
  489. end
  490.  
  491. tempdata_dir=translate(tempdata_dir,'\','/')
  492.    tempdata_dir=strip(tempdata_dir,'t','\')
  493. if dosisdir(tempdata_dir)=0 then do
  494.      call pmprintf(' SRE-Filter monitor: Warning, could not find tempdata_dir: 'tempdata_dir)
  495.      tempdata_dir=datadir()
  496.  
  497. end
  498.  
  499. tempfile_dir=translate(tempfile_dir,'\','/')
  500.    tempfile_dir=strip(tempfile_dir,'t','\')
  501. if dosisdir(tempfile_dir)=0 then do
  502.      call pmprintf(' SRE-Filter monitor: Warning, could not find tempfile_dir: 'tempfile_dir)
  503.      tempfile_dir=servdir
  504. end
  505.  
  506. cgi_bin_dir=translate(cgi_bin_dir,'\','/')
  507.    cgi_bin_dir=strip(cgi_bin_dir,'t','\')
  508.    if cgi_bin_dir="" then cgi_bin_dir=0
  509. if dosisdir(cgi_bin_dir)=0 then do
  510.      call pmprintf(' SRE-Filter monitor: Warning, could not find cgi-bin-dir: 'cgi_bin_dir)
  511.      cgi_bin_dir=' '
  512. end  /* Do */
  513.  
  514.  
  515. /* chek other stuff */
  516.  
  517. HOME_DIR=STRIP(HOME_DIR)
  518. inhouse_privs=translate(inhouse_privs)
  519.    if inhouse_privs=0 then inhouse_privs=" "
  520. public_privs=translate(public_privs)
  521.    if public_privs=0 then public_privs=" "
  522.  
  523. virtual_file=strip(virtual_file)
  524.  
  525. ALLOW_ACCESS=TRANSLATE(STRIP(ALLOW_ACCESS))
  526. if allow_access="Y" | allow_access=1 then allow_access="YES"
  527.  
  528. do_Htaccess=is_true(do_htaccess,'Y YES 1')
  529.  
  530.  
  531. ssi_cache_on=is_true(ssi_cache_on,'Y YES 1 ')
  532.  
  533. ssi_shtml_only=is_true(ssi_shtml_only,'Y YES 1')
  534. DNS_CHECK=translate(dns_check)
  535. if upload_log="" then upload_log=0
  536. if datatype(upload_maxsize)<>'NUM' then
  537.     upload_maxsize=50
  538. if datatype(upload_minfree)<>'NUM' then
  539.     upload_minfree=20000
  540.  
  541. if datatype(ssi_cache_size)<>'NUM' then
  542.    ssi_cache_size=5000
  543.  
  544. if datatype(ssi_cache_duration)<>'NUM' then ssi_cache_duration=1
  545. if ssi_cache_duration=0 then ssi_cache_duration=1000000 /* infiinte*/
  546.  
  547. if wordpos(ssi_cache_stamp,'TIME DATE TIMEDATE DATETIME SIZE ALL')=0 then
  548.    ssi_cache_stamp='ALL'
  549.  
  550.  
  551. pre_filter=translate(pre_filter)
  552. post_filter=is_true(post_filter,'Y YES 1')
  553.  
  554. if smtp_gateway=" " then smtp_gateway=0
  555.  
  556. hit_owner_suppress=is_true(hit_owner_suppress,'Y YES 1')
  557. write_logs=is_true(write_logs,'Y YES 1')
  558.  
  559. if upper(hit_cache_len)="FILE" then do
  560.    nop
  561. end  /* Do */
  562.  
  563. else do
  564.   if datatype(hit_cache_len)<>'NUM' then do 
  565.      hit_cache_len=0
  566.   end
  567.   else do
  568.     hit_cache_len=min(hit_cache_len,50)  /* 50 k max */
  569.   end  /* Do */
  570. end
  571.  
  572. if datatype(hit_cache_DURATION)<>'NUM' then do
  573.      hit_cache_DURATION=15
  574. END
  575. ELSE DO
  576.    HIT_cache_DURATION=MAX(1,HIT_cache_DURATION)
  577. end  /* Do */
  578.  
  579.  
  580. if the_realm=0 then do
  581.   if  symbol('inhouse_name')<>"VAR"  then
  582.         the_realm=inhouse_name
  583.   else
  584.        the_realm="OUR WEB SITE"           /* name we call "ourselves" */
  585. end
  586.  
  587.  
  588. RECORD_OPTION=TRANSLATE(RECORD_OPTION)
  589. if wordpos(record_option,'YES YES_ALL FILE ')=0 then
  590.      record_option="NO"              /* recording option on?*/
  591.  
  592. gots=0
  593.  
  594. hosts.0=0
  595. do m=1 to 100000
  596.    if symbol('hosts.m')<>"VAR" then leave
  597.    if hosts.m=0 then leave
  598.    hosts.0=m
  599. end /* do */
  600.  
  601.  
  602. ralphie=cvtails('DELIM_1',dlist)
  603.  
  604. delims=0
  605. do m=1 to ralphie
  606.  
  607.    a1=dlist.m
  608.    a2=translate(a1,' ','.')
  609.    if words(a2)=1 then do
  610.         if datatype(a1)='NUM' then do
  611.            tmp1=DELIM_1.a1
  612.            if tmp1='0' then iterate
  613.            delims=max(delims,a1)
  614.         end  /* Do */
  615.     end  /* Do */
  616.    if words(a2)=2 then do
  617.         if datatype(word(a2,1))='NUM' then do
  618.            ahost=word(a2,2)
  619.            tmp1=DELIM_1.a1
  620.            if tmp1='0' then iterate
  621.            if symbol('DELIMS.'||ahost)='VAR' then
  622.                 delims.ahost=max(delims.ahost,word(a2,1))
  623.            else
  624.                 delims.ahost=word(a2,1)
  625.         end  /* Do */
  626.     end  /* Do */
  627. end
  628.  
  629.  
  630.  
  631. crlf='0d0a'x
  632. FPO=MAKE_HEAD_FOOT()
  633.  
  634. /* creates HEADERS FOOTERS HEADERS. FOOTERS. HEADLIST. FOOTLIST. NHEADS NFOOTS */
  635.  
  636. auto_header=upper(auto_header)
  637.  
  638. /* check for "send in pieces "  --no fix_expire,  no 2nd delimiter
  639.    NOW DONE IN SSI routine
  640. if delims=1 &  fix_expire=0  & do_Send_piece=1 then
  641.    send_piece=1
  642. else
  643.   send_piece=0
  644. */
  645.  
  646. suppress_alias=0 ; suppress_virtual=0 ; suppress_access=0
  647. suppress_user=0 ; check_doq=0
  648. if (alias_file=" " | alias_file=0)  then
  649.         suppress_alias=1
  650. if virtual_file=" " | virtual_file=0 then
  651.         suppress_virtual=1
  652. if (user_file=" " | user_file=0 ) then
  653.         suppress_user=1
  654. if access_file=" "| access_file=0  then
  655.         suppress_access=1
  656. /*say suppress_alias suppress_user suppress_access suppress_virtual*/
  657.  
  658. if (suppress_alias+suppress_user+suppress_access+suppress_virtual)>0 then
  659.    check_doq=1
  660.  
  661. return 0
  662.  
  663.  
  664. /* ------------------------------------------------- */
  665. /* routine to set default initfilt.80  */
  666. /* ------------------------------------------------- */
  667. default_initfilt:
  668.  
  669. /* variables that can be changed by configure */
  670.  
  671. display_env=0
  672. checklog='NO'           /* Free entry */
  673. the_realm=0           /* name we call "ourselves" , 0 will be replaced generically*/
  674. home_name=" "              /* The colloquial (not necessrily ip) domain name */
  675. auto_header="NO"        /* no, always, head */
  676. AUTO_NAME=0         /* 0=none, or a list with *.HTM, !CREATE, file.nam */
  677. CHECK_alias="YES"   /* : YES=yes, NO=None, HTML=.HTM (or .HTML)  */
  678. not_found_url='<a href="/"> Visit the home_name home page? </a> '   /* Message that is sent with no such url  */
  679. pre_filter="NO"         /* no  yes first */
  680. post_filter="NO"
  681. noext_type="HTM"  /* NONE DIR HTM or HTML REDIR */
  682. record_option="NO"   /* YES, YES_ALL */
  683. allow_access="YES"  /* access control on file transfers (YES=none) */
  684. default='index.htm'     /* use if default home page selected */
  685. add_privs_prefix='!'
  686. hosts.1=0               /* list of alternatme hosts */
  687. inhouse_privs=" INHOUSE "    /* additional privs for inhouseips and owners */
  688. public_privs=" PUBLIC "    /* additional privs for veryone */
  689. inhouse.1=" (INHOUSE User) "   /* Used with REPLACE:INHOUSE1, etc. */
  690. suPEruser.1="(Super User)"
  691. headers.1=0  /* stuff to put at beginning / end of */
  692. footers.1=0  /* all htm documents. 0= nothing */
  693. OPTION_hit_line=":: still access # "
  694. webmaster=' (no contact available) '
  695. owners   = 'none'  /* Owners are automatically superusers (seperate with spaces) */
  696. inhouse_privs="INHOUSE"
  697. public_privs="PUBLIC"
  698. smtp_gateway=" "    /* smtp_gateway, used by post-filter "e-mail alert" facility */
  699.  
  700. /* Directories and files */
  701.  
  702. cgi_bin_dir="\goserv\cgi-bin"                   /* if 0, do not emulate cgi-bin */
  703.  
  704. messbox_dir="\GOSERV\MESSAGE"                        /* SRE-Filter data */
  705. maibox_dir="\GOSERV\MAIL"
  706. upload_dir="\GOSERV\UPLOAD"
  707. config_dir='\GOSERV\CONFIGS'
  708. tempfile_dir="\gohttp\temp"
  709. tempdata_dir="\goserv\temp"
  710. home_dir="\gohttp\home"
  711. workdata_dir="\GOSERV\DATA";
  712.  
  713. counter_file="\GOSERV\data\COUNTER.CNT"
  714. record_all_file="\GOSERV\DATA\RECRDALL.CNT"
  715. sendfile_file="\GOSERV\DATA\SENDFILE.CTL"
  716.  
  717. logon_fail_file=0
  718. access_fail_file=0
  719.  
  720. htaccess_file=0
  721. do_htaccess=0
  722.  
  723. access_file="\GOSERV\DATA\ALL_FILE.CTL"
  724. accept_range="NO"
  725. check_add_privs='NO'
  726. use_stdout="YES"
  727. add_user_name='YES'
  728. add_resource_name='NO'
  729. virtual_file="\GOSERV\data\VIRTUAL.IN"
  730. user_file="\GOSERV\data\USERS.IN"
  731. interpret_file="\GOSERV\data\INTERPET.IN"
  732.  
  733. repstrgs_file="\GOSERV\data\REPSTRGS.IN"
  734. alias_file="\GOSERV\data\ALIASES.IN"
  735. upload_log="\GOSERV\DATA\UPLOAD.LOG"
  736.  
  737. /* variables not changed by configure */
  738. max_pointdist=50     /* max distance acceptable for a "assign to point" in ncsa map */
  739. ssi_shtml_only='NO'    /* yes no, ssi on .sht or .shtml only */
  740. ssi_cache_on='YES'    /* use ssi-caching (no, yes) */
  741.  
  742. fix_expire=0    /* set to non zero to redo response headers */
  743. do_send_piece='NO' /* yes to allow "send in pieces",no to disallow */
  744. no_include="NO"   /* yes no , disallow all ssi */
  745. no_processing="NO"   /* if yes, then no server side processing allowed */
  746. no_interpret_code='NO'
  747. delim_1.1='<!--'     /* the left and right side "keyphrase" delimeters */
  748. delim_2.1='-->'      /* can be any string combo */
  749. upload_maxsize=50             /* max size that a uploaded file can be, in k */
  750. upload_minfree=20000        /* minimum free in K, in dowload_dir, AFTER file upload */
  751. postfilter_name="POSTFILT"
  752. prefilter_name="PREFILTR"
  753.  
  754. interpret_types=' PL=PERL5 '  /* used by CGI-BIN to invoke alternate interpeters */
  755.  
  756. dir_exclusion='HTACCESS. /PRIVATE *.CNT '
  757. DIR_OPTIONS='  notime auto_describe describe=describe.txt no_recurse_dir  '
  758.  
  759.  
  760.  
  761. check_doq=0
  762. verbose=1
  763.  
  764. hit_cache_len=0        /* not on (otherwise, # of k) */
  765. hit_cache_duration=15     /* # of minutes */
  766. hit_cache=' '
  767. hit_owner_suppress='YES'
  768. write_logs='YES'
  769.  
  770.  
  771. return 0
  772.  
  773.  
  774. /* ----------------------------- */
  775. /* save some initfilt varibles to the environment */
  776. /* ----------------------------- */
  777. save_envstuff:
  778.  
  779. ALIST='CHECKLOG AUTO_HEADER DO_SEND_PIECE VERBOSE DNS_CHECK ALLOW_ACCESS '
  780. do mm=1 to words(alist)
  781.   call save_em(word(alist,mm))
  782. end
  783.  
  784.  
  785. call value enVadd||'SUPPRESS_ALIAS',suppress_alias,'os2environment'
  786. call value enVadd||'suppress_virtual',suppress_virtual,'os2environment'
  787. call value enVadd||'suppress_access',suppress_access,'os2environment'
  788. call value enVadd||'suppress_user',suppress_user,'os2environment'
  789. call value enVadd||'CHECK_DOQ',CHECK_DOQ,'os2environment'
  790. call value enVadd||'LOADTHRESHOLD',loadthreshold,'os2environment'
  791. call value enVadd||'BACKUPSERVERLIST',backupserverlist,'os2environment'
  792. call value enVadd||'SAVE_STATE',save_state,'os2environment'
  793. call value enVadd||'NO_NO_RECORD',no_no_record,'os2environment'
  794. call value enVadd||'MESSAGE_SCRAMBLE',MESSAGE_SCRAMBLE,'os2environment'
  795. call value enVadd||'SSI_EXTENSIONS',ssi_extensions,'os2environment'
  796.  
  797.  
  798. ALIST='AUTO_NAME DEFAULT CHECK_ALIAS NOEXT_TYPE ADD_PRIVS_PREFIX INTERPRET_TYPES DIR_OPTIONS DIR_EXCLUSION '
  799. do mm=1 to words(alist)
  800.   call save_em(word(alist,mm))
  801. end
  802.  
  803. ALIST='PRE_FILTER PREFILTER_NAME POST_FILTER POSTFILTER_NAME  '
  804. do mm=1 to words(alist)
  805.   call save_em(word(alist,mm))
  806. end
  807.  
  808. call value envadd||'HEADERS',headers,'os2environment'
  809. call value envadd||'FOOTERS',footers,'os2environment'
  810.  
  811. do mm=1 to nheads
  812.    foo=strip(headlist.mm)
  813.    aval0=aheaders.foo
  814.    tty=strip(envadd||'HEADERS.'||foo)
  815.    call value tty,aval0,'os2environment'
  816. end /* do */
  817. do mm=1 to nfoots
  818.    foo=strip(footlist.mm)
  819.    aval0=afooters.foo
  820.    call value envadd||'FOOTERS.'||foo,aval0,'os2environment'
  821. end /* do */
  822.  
  823. alist='THE_REALM HOME_NAME NOT_FOUND_URL PUBLIC_PRIVS INHOUSE_PRIVS OPTION_HIT_LINE LOGON_FAIL_FILE ACCESS_FAIL_FILE'
  824. do mm=1 to words(alist)
  825.   call save_em(word(alist,mm))
  826. end
  827.  
  828. alist='WEBMASTER OWNERS SMTP_GATEWAY ACCEPT_RANGE USE_STDOUT ADD_USER_NAME ADD_RESOURCE_NAME '
  829. do mm=1 to words(alist)
  830.   call save_em(word(alist,mm))
  831. end
  832.  
  833.  
  834. call value envadd||'HOSTS.0',hosts.0,'os2environment'
  835.  
  836. ALIST='MAX_POINTDIST NO_INCLUDE NO_INTERPRET_CODE NO_PROCESSING FIX_EXPIRE SSI_SHTML_ONLY CHECK_ADD_PRIVS SSI_CACHE_ON '
  837. do mm=1 to words(alist)
  838.   call save_em(word(alist,mm))
  839. end
  840.  
  841. ALIST='UPLOAD_MINFREE UPLOAD_MAXSIZE HOME_DIR HIT_CACHE_LEN HIT_CACHE_DURATION HIT_CACHE WRITE_LOGS HIT_OWNER_SUPPRESS SSI_CACHE_SIZE SSI_CACHE_DURATION SSI_CACHE_STAMP '
  842. do mm=1 to words(alist)
  843.   call save_em(word(alist,mm))
  844. end
  845.  
  846. call value envadd||'cgi_bin_dir',cgi_bin_dir,'os2environment'
  847.  
  848. tempfile_dir=upper(strip(tempfile_dir))
  849. call value envadd||'tempfile_dir',tempfile_dir,'os2environment'
  850.  
  851. tempdata_dir=upper(strip(tempdata_dir))
  852. call value envadd||'tempdata_dir',tempdata_dir,'os2environment'
  853.  
  854. upload_dir=upper(strip(upload_dir))
  855. call value envadd||'upload_dir',upload_dir,'os2environment'
  856.  
  857. messbox_dir=upper(strip(messbox_dir))
  858. call value envadd||'messbox_dir',messbox_dir,'os2environment'
  859.  
  860. config_dir=upper(strip(config_dir))
  861. call value envadd||'config_dir',config_dir,'os2environment'
  862.  
  863.  
  864. workdata_dir=upper(strip(workdata_dir))
  865. call value envadd||'workdata_dir',workdata_dir,'os2environment'
  866.  
  867.  
  868. mailbox_dir=upper(strip(mailbox_dir))
  869. call value envadd||'mailbox_dir',mailbox_dir,'os2environment'
  870.  
  871.  
  872. call value envadd||'SERVDIR',servdir,'os2environment'
  873.  
  874. call value envadd||'INITFILT_FILE',INIT_file,'os2environment'
  875. call value envadd||'USER_FILE',user_file,'os2environment'
  876. call value envadd||'ACCESS_FILE',access_file,'os2environment'
  877. call value envadd||'VIRTUAL_FILE',virtual_file,'os2environment'
  878. call value envadd||'ALIAS_FILE',alias_file,'os2environment'
  879. call value envadd||'REPSTRGS_FILE',repstrgs_file,'os2environment'
  880.  
  881. call value envadd||'INTERPRET_FILE',interpret_file,'os2environment'
  882. call value envadd||'SENDFILE_FILE',sendfile_file,'os2environment'
  883.  
  884. call value envadd||'HTACCESS_FILE',htaccess_file,'os2environment'
  885. call value envadd||'DO_HTACCESS',DO_htaccess,'os2environment'
  886.  
  887. /* determine # of public_urls (non host specific) -- used by srefquik.80 */
  888. /* and while we are at it, fix 'em up */
  889. aa='public_urls.'
  890. nin=0
  891. do mm=1 to 10000
  892.       moe=aa||mm
  893.       if upper(symbol(moe))<>"VAR" then leave
  894.       interpret 'tt='||moe
  895.       if tt="" | tt=0 then  leave
  896.       nin=nin+1
  897. end
  898. public_urls.0=nin
  899.  
  900. /*call save_em('public_urls.')*/
  901.  
  902. /* IP_address,  host_nickname,  default_directory */
  903. call pmprintf('SRE-Filter monitor: looking up '||hosts.0||' HOST IP addresses')
  904. do m=1 to hosts.0
  905.    aah=upper(hosts.m)
  906.    aah=translate(aah,' ',',')
  907.    parse upper var aah  sname  hn  adir
  908.    SNAME=STRIP(SNAME)
  909.  
  910.    hn=upper(hn)
  911.    adir=translate(strip(adir),'\','/'); adir=strip(adir,'t','\')||'\'
  912.  
  913. /* create ip number lookup table */
  914.     isnumip=verify(SNAME,'1234567890.')
  915.     if isnumip=0 then         /* is numeric ip */
  916.            astat=sockgethostbyaddr(sname,'stuff.!')
  917.     else
  918.           astat=sockgethostbyname(sname,'stuff.!')
  919.  
  920. /* create HOST.n and HOSTS_IP.n :
  921.    HOST.N will contain  ip_name , host_nickname, default dir
  922.         where ip_name is the name supplied in the HOSTS. variable,
  923.         OR, if a numeric ip address was supplied, the name associated
  924.             with the numeric  ip address ( a socket call is made)
  925.         BUT, if no name can be found for this IP address, the IP address
  926.              is used
  927.    HOSTS_IP  is a simple lookup table -- it's computed here to avoid
  928.              lengthy socket calls.  The structure should be:
  929.                 numeric_ip_address ip_name
  930.              If a name is give, the address is looked up,
  931.              if a numeric address is given, the name is looked up
  932.              If no address can be found for a name, the entry is left
  933.              blank.  Similarly, it a name can not be found for a
  934.             numeric address, the entry is left blank.
  935.             In other words: both have to exist, else a blank entry is used.
  936. */
  937.  
  938. /* save basic name and ip */
  939.     if astat=1  then do
  940.            booz=stuff.!addr||' '||upper(stuff.!name)
  941.            if isnumip=0 then
  942.                name1=strip(upper(stuff.!name))
  943.            else
  944.                 name1=strip(upper(sname))
  945.     end
  946.     else do
  947.            booz=' '
  948.            name1=sname
  949.    end
  950.    call value envadd||'HOSTS_IP.'||m,booz,'os2environment'
  951.    aah=name1||','||hn||','||adir
  952.    call value envadd||'HOSTS.'||m,aah,'os2environment'
  953. end /* do  HOSTS */
  954.  
  955. call save_em('inhouseips.')
  956. do m=1 to plist.0            /* fix and save INHOUSEIPS */
  957.   t1=plist.m
  958.   anval=inhouseips.t1
  959.   w1=word(anval,1)   /* look for host nickname */
  960.   if right(w1,2)='//' then do
  961.        geti=2
  962.   end
  963.   else do
  964.      geti=1
  965.   end
  966.   call value envadd||'inhouseips.'||t1,anval,'os2environment'
  967. end
  968.  
  969. call save_em('unallowedips.')
  970. do m=1 to plist.0            /* fix and save unallowedIPS */
  971.   t1=plist.m
  972.   anval=unallowedips.t1
  973.   w1=word(anval,1)   /* look for host nickname */
  974.   if right(w1,2)='//' then do
  975.        geti=2
  976.   end
  977.   else do
  978.      geti=1
  979.   end
  980.   if verify(word(anval,geti),'1234567890.')<>0 then do  /* convert numeric ip */
  981.       astat=sockgethostbyname(word(anval,geti),'stuff.!')
  982.       if astat=1 then do
  983.            if geti=1 then do
  984.               parse var anval vv anval
  985.               anval=stuff.!addr||' '||anval
  986.             end
  987.             else do
  988.                parse var anval vv1 vv2  anval
  989.                anval=vv1||' '||stuff.!addr||' '||anval
  990.             end  /* Do */
  991.       end  /* Do */
  992.   end
  993.   call value envadd||'unallowedips.'||t1,anval,'os2environment'
  994. end
  995.  
  996. do m=1 to delims
  997.   if symbol('DELIM_1.'||m)<>'VAR' then iterate
  998.   call value envadd||'DELIM_1.'||m,delim_1.m,'os2environment'
  999.   if symbol('DELIM_2.'||m)<>'VAR' then iterate
  1000.   call value envadd||'DELIM_2.'||m,delim_2.m,'os2environment'
  1001. end
  1002. call value envadd||'DELIMS',delims,'os2environment'
  1003.  
  1004. ralphie=cvtails('DELIMS',dlist)
  1005. do mm=1 to ralphie
  1006.    booboo=dlist.mm
  1007.    call value envadd||'DELIMS.'||booboo,delims.booboo,'os2environment'
  1008.    do m=1 to delims.booboo
  1009.     if symbol('DELIM_1.'||m||'.'||booboo)<>'VAR' then iterate
  1010.      call value envadd||'DELIM_1.'||m||'.'||booboo,delim_1.m.booboo,'os2environment'
  1011.     if symbol('DELIM_2.'||m||'.'||booboo)<>'VAR' then iterate
  1012.      call value envadd||'DELIM_2.'||m||'.'||booboo,delim_2.m.booboo,'os2environment'
  1013.    end
  1014. end /* do */
  1015.  
  1016.  
  1017. /* fix up public_urls */
  1018. num_public_Urls=cvtails(PUBLIC_URLS,foo1)
  1019. if num_public_urls>0 then do    /* clean em up */
  1020.    do mm=1 to num_public_urls
  1021.       tl1=foo1.mm
  1022.       vl=public_urls.tl1
  1023.       if pos('?',vl)>1 then do
  1024.           parse var vl vla '?' vlb
  1025.           vla=strip(translate(vla,'/','\'))
  1026.           if length(vla)>0 then 
  1027.               if  abbrev(vla,'/')=1 then vla=substr(vla,2)
  1028.           v1=vla||'?'||vlb
  1029.       end
  1030.       else do
  1031.           vl=strip(translate(vl,'/','\'))
  1032.           if length(vl)>0 then 
  1033.               if  abbrev(vl,'/')=1 then vl=substr(vl,2)
  1034.       end  /* Do */
  1035.       public_urls.tl1=vl
  1036.    end /* do */
  1037. end  /* Do */
  1038. call save_em('public_urls.')
  1039.  
  1040. call save_em('NUM_PUBLIC_URLS')
  1041. call pmprintf(' #  of public urls = 'num_public_Urls)
  1042.  
  1043. CALL SAVE_EM('SUPERUSER')
  1044. CALL SAVE_EM('INHOUSE')
  1045.  
  1046. call pmprintf(' SRE-Filter monitor: number of hosts= 'hosts.0 )
  1047. return 0
  1048.  
  1049.  
  1050. /* ----------------------------------------------------------------------- */
  1051. /* --  copy repstrgs file to environment */
  1052. /* ----------------------------------------------------------------------- */
  1053.  
  1054. chk_repstrgs:
  1055. parse arg resetit
  1056.  
  1057. if repstrgs_file=" " then
  1058.   return 0
  1059. oy=stream(repstrgs_file,'c','query exists')
  1060. if oy="" then do
  1061.    CALL PMPRINTF("SRE-Filter monitor: Replacement strings file not found, "|| get_file)
  1062.    return -1
  1063. end
  1064.  
  1065. /* yep, reinitialize repstrgs file (set semaphore first */
  1066. ause=fileread(repstrgs_file,'filelines',,'E')
  1067. If (ause=0) then  do               /*no such file,*/
  1068.       CALL PMPRINTF("SRE-Filter monitor: Replacement strings file unusable, "|| repstrgs_file)
  1069.       return -1
  1070. end
  1071.  
  1072. crlf='0d0a'x
  1073. j=0
  1074. /* zap current list of repstrings variables */
  1075. do rr=1 to repsvars.0
  1076.   call value repsvars.rr,' ','os2environment'
  1077. end
  1078. repsvars.0=0
  1079. do mm=1 to filelines.0
  1080.   goo=strip(filelines.mm)
  1081.   if goo="" | left(goo,1)=";" then
  1082.        iterate
  1083.  
  1084.   parse var goo aname avalue
  1085.   aname=envadd||upper(aname)
  1086.   t1=value(aname,,'os2environment')
  1087.   if t1=' ' then do
  1088.       t1=avalue
  1089.       j=j+1
  1090.       repsvars.j=aname
  1091.       repsvars.0=j
  1092.   end
  1093.   else
  1094.         t1=t1||crlf||avalue
  1095.  
  1096.   call value aname,t1,'os2environment'
  1097. end
  1098. call pmprintf(' SRE-Filter Monitor: loaded replacements strings: 'j)
  1099. return j
  1100.  
  1101.  
  1102. /* ----------------------------------------------------------------------- */
  1103. /* -- See if a "generic" YES answer. If so, return 1 */
  1104. /* ----------------------------------------------------------------------- */
  1105. is_true:procedure
  1106. parse upper arg ans,anslist
  1107. if wordpos(ans,anslist)>0 then
  1108.  return 1
  1109. else
  1110.  return 0
  1111.  
  1112.  
  1113.  
  1114. /*=========     Start various threads   ===================== */
  1115.  
  1116.  
  1117. /* ------------------------------------------------------------ */
  1118. /* start access processor thread */
  1119. start_access:
  1120. parse arg resetit
  1121.  
  1122. if access_file= ' ' | SUPPRESS_ACCESS=1 then
  1123.       return 0
  1124. oy=stream(access_file,'c','query exists')
  1125. if oy="" then do
  1126.    CALL PMPRINTF("SRE-Filter monitor: access file not found, "|| access_file)
  1127.    access_file=' '
  1128.    return -1
  1129. end
  1130.  
  1131. arxx=servdir||'\acceschk.rxx'
  1132. usequeue='SREF_'||serverport||'_ACCESS'
  1133. usesem='\SEM32\SREF_'||serverport||'_ACCESS'
  1134.  
  1135. if resetit=1 then do            /* already opened --just send a *RESET* */
  1136.    a=rxqueue('s',usequeue)
  1137.    push '1, 1, 2, *RESET* ' access_file
  1138.    return 1
  1139. end
  1140.  
  1141. /* if here, first time */
  1142.  
  1143. a=rxqueue('d',usequeue)
  1144. a=rxqueue('c',usequeue)
  1145. if a<>usequeue then do
  1146.   bb=rxqueue('d','a')
  1147.   a=rxqueue('s',usequeue)
  1148.   do queued()
  1149.        pull
  1150.   end /* do */
  1151. end
  1152.  
  1153. a=eventsem_close(usesem)
  1154. A=EVENTSEM_CREATE(USESEM)
  1155. IF A<>0 then DO
  1156.     call pmprintf(' SRE-Filter monitor: Error creating access semaphore: 'A' 'usesem)
  1157.     access_file=' '
  1158.     return -1
  1159. end
  1160. access_tid=rexxthread('f',arxx,access_file,usequeue,USESEM,max_semwait)
  1161. if access_tid=0 then do
  1162.    call pmprintf(' SRE-Filter monitor: Could not open access thread 'arxx)
  1163.     access_file=' '
  1164.    return -1
  1165. end
  1166.  
  1167. return 1
  1168.  
  1169. /* ---------------- */
  1170. /* start alias processor thread */
  1171. start_alias:
  1172. parse arg resetit
  1173.  
  1174. if alias_file= ' ' | SUPPRESS_ALIAS=1 then
  1175.       return 0
  1176. oy=stream(alias_file,'c','query exists')
  1177.  
  1178. if oy="" then do
  1179.    CALL PMPRINTF("SRE-Filter monitor: alias file not found, "|| alias_file)
  1180.    alias_file=' '
  1181.    return -1
  1182. end
  1183.  
  1184. arxx=servdir||'\aliaschk.rxx'
  1185. usequeue='SREF_'||serverport||'_ALIAS'
  1186. usesem='\SEM32\SREF_'||serverport||'_ALIAS'
  1187.  
  1188. if resetit=1 then do            /* already opened --just send a *RESET* */
  1189.    a=rxqueue('s',usequeue)
  1190.    push '1,1,2,*RESET* ' alias_file
  1191.    foo=eventsem_post(usesem)
  1192.    return 1
  1193. end
  1194.  
  1195. /* if here, first time */
  1196.  
  1197. a=rxqueue('d',usequeue)
  1198. a=rxqueue('c',usequeue)
  1199. if a<>usequeue then do
  1200.   bb=rxqueue('d','a')
  1201.   a=rxqueue('s',usequeue)
  1202.   do queued()
  1203.        pull
  1204.   end /* do */
  1205. end
  1206.  
  1207. a=eventsem_close(usesem)
  1208. A=EVENTSEM_CREATE(USESEM)
  1209. IF A<>0 then DO
  1210.     call pmprintf(' SRE-Filter monitor: Error creating alias semaphore: 'A' 'usesem)
  1211.     return 0
  1212. end
  1213. alias_tid=rexxthread('f',arxx,alias_file,usequeue,USESEM,max_semwait)
  1214. if alias_tid=0 then do
  1215.    call pmprintf(' SRE-Filter monitor: Could not open alias thread 'arxx)
  1216.    return 0
  1217. end
  1218.  
  1219. return 1
  1220.  
  1221.  
  1222.  
  1223. /* ---------------- */
  1224. /* start virtual dir processor thread */
  1225. start_virtual:
  1226. parse arg resetit
  1227.  
  1228. IF VIRTUAL_FILE="" | SUPPRESS_VIRTUAL=1 then RETURN 0
  1229.  
  1230.  
  1231. dlistx=upload_dir||' '||cgi_bin_dir||'  '||servdir||' '
  1232. dlistx=dlistx||translate(datadir(),'\','/')
  1233.  
  1234.  
  1235. arxx=servdir||'\virtchk.rxx'
  1236. usequeue='SREF_'||serverport||'_VIRTUAL'
  1237. usesem='\SEM32\SREF_'||serverport||'_VIRTUAL'
  1238.  
  1239. if resetit=1 then do            /* already opened --just send a *RESET* */
  1240.    call pmprintf(' resetting virtual file 'virtual_file)
  1241.    a=rxqueue('s',usequeue)
  1242.    push '1,1,2, *RESET* ' virtual_file
  1243.    foo=eventsem_post(usesem)
  1244.    return 1
  1245. end
  1246.  
  1247. if virtual_file= ' ' then
  1248.       return 0
  1249. oy=stream(virtual_file,'c','query exists')
  1250. if oy="" then do
  1251.    CALL PMPRINTF("SRE-Filter monitor: virtual file not found, "|| virtual_file)
  1252.    virtual_file=' '
  1253.    return 0
  1254. end
  1255.  
  1256.  
  1257.  
  1258. /* if here, first time */
  1259.  
  1260. a=rxqueue('d',usequeue)
  1261. a=rxqueue('c',usequeue)
  1262. if a<>usequeue then do
  1263.   bb=rxqueue('d','a')
  1264.   a=rxqueue('s',usequeue)
  1265.   do queued()
  1266.        pull
  1267.   end /* do */
  1268. end
  1269.  
  1270. a=eventsem_close(usesem)
  1271. A=EVENTSEM_CREATE(USESEM)
  1272. IF A<>0 then DO
  1273.     call pmprintf(' SRE-Filter monitor:Error creating virtual semaphore: 'A' 'usesem)
  1274.     return 0
  1275. end
  1276. mm1=max_semwait
  1277. virtual_tid=rexxthread('f',arxx,virtual_file||' '||dlistx,usequeue,USESEM,mm1)
  1278. if virtual_tid=0 then do
  1279.    call pmprintf(' SRE-Filter monitor:Could not open virtual thread 'arxx)
  1280.    return 0
  1281. end
  1282.  
  1283. return 1
  1284.  
  1285.  
  1286.  
  1287.  
  1288.  
  1289. /* ---------------- */
  1290. /* start virtual dir processor thread */
  1291. start_ssicache:
  1292. if ssi_cache_size="" then return 0
  1293.  
  1294. arxx=servdir||'\ssicache.rxx'
  1295. usequeue='SREF_'||serverport||'_SSICACHE'
  1296. usesem='\SEM32\SREF_'||serverport||'_SSICACHE'
  1297.  
  1298.  
  1299. a=rxqueue('d',usequeue)
  1300. a=rxqueue('c',usequeue)
  1301. if a<>usequeue then do
  1302.   bb=rxqueue('d','a')
  1303.   a=rxqueue('s',usequeue)
  1304.   do queued()
  1305.        pull
  1306.   end /* do */
  1307. end
  1308.  
  1309. a=eventsem_close(usesem)
  1310. A=EVENTSEM_CREATE(USESEM)
  1311. IF A<>0 then DO
  1312.     call pmprintf(' SRE-Filter monitor:Error creating ssi-cache semaphore:'usesem)
  1313.     return 0
  1314. end
  1315. mm1=max_semwait
  1316. ssicache_tid=rexxthread('f',arxx,tempdata_dir,usequeue,USESEM,mm1,serverport,ssi_cache_size,ssi_cache_duration,ssi_cache_stamp)
  1317. if ssicache_tid=0 then do
  1318.    call pmprintf(' SRE-Filter monitor:Could not open ssi-cache thread 'arxx)
  1319.    return 0
  1320. end
  1321.  
  1322. return 1
  1323.  
  1324.  
  1325.  
  1326.  
  1327. /* ---------------- */
  1328. /* start user check processor thread */
  1329. start_user:
  1330. parse arg resetit
  1331. if user_file= ' ' | SUPPRESS_USER=1 then
  1332.       return 0
  1333.  
  1334. oy=stream(user_File,'c','query exists')
  1335. if oy="" then do
  1336.    CALL PMPRINTF("SRE-Filter monitor: userl file not found, "||user_file)
  1337.     user_file=' '
  1338.    return -1
  1339. end
  1340.  
  1341. arxx=servdir||'\userchk.rxx'
  1342. usequeue='SREF_'||serverport||'_USER'
  1343. usesem='\SEM32\SREF_'||serverport||'_USER'
  1344.  
  1345. if resetit=1 then do            /* already opened --just send a *RESET* */
  1346.    a=rxqueue('s',usequeue)
  1347.    push '1,1,2, *RESET* ' user_File
  1348.    foo=eventsem_post(usesem)
  1349.    return 1
  1350. end
  1351.  
  1352. /* if here, first time */
  1353. a=rxqueue('d',usequeue)
  1354. a=rxqueue('c',usequeue)
  1355. if a<>usequeue then do
  1356.   bb=rxqueue('d','a')
  1357.   a=rxqueue('s',usequeue)
  1358.   do queued()
  1359.        pull
  1360.   end /* do */
  1361. end
  1362.  
  1363. a=eventsem_close(usesem)
  1364. A=EVENTSEM_CREATE(USESEM)
  1365. IF A<>0 then DO
  1366.     call pmprintf(' SRE-Filter monitor:Error creating user semaphore: 'A' 'usesem)
  1367.     return 0
  1368. end
  1369. user_tid=rexxthread('f',arxx,user_file,usequeue,USESEM,max_semwait,logon_limit)
  1370. if user_tid=0 then do
  1371.    call pmprintf(' SRE-Filter monitor:Could not open user thread 'arxx)
  1372.    return 0
  1373. end
  1374.  
  1375.  
  1376. return 1
  1377.  
  1378.  
  1379. /* ---------------- */
  1380. /* start postfilter / recordall processor thread */
  1381. start_postf:
  1382. parse arg resetit
  1383.  
  1384. arxx=servdir||'\postfchk.rxx'
  1385. usequeue='SREF_'||serverport||'_postf'
  1386. usesem='\SEM32\SREF_'||serverport||'_postf'
  1387.  
  1388. a=rxqueue('d',usequeue)
  1389. a=rxqueue('c',usequeue)
  1390. if a<>usequeue then do
  1391.   bb=rxqueue('d','a')
  1392.   a=rxqueue('s',usequeue)
  1393.   do queued()
  1394.        pull
  1395.   end /* do */
  1396. end
  1397.  
  1398. a=eventsem_close(usesem)
  1399. A=EVENTSEM_CREATE(USESEM)
  1400. IF A<>0 then DO
  1401.     call pmprintf('SRE-Filter monitor: Error creating postfilter semaphore: 'A' 'usesem)
  1402.     return 0
  1403. end
  1404.  
  1405. mm1=max_semwait*1.5
  1406. postf_tid=rexxthread('f',arxx,usequeue,USESEM,mm1,record_cache_lines' 'workdata_dir)
  1407. if postf_tid=0 then do
  1408.    call pmprintf(' SRE-Filter monitor:Could not open postfilter thread 'arxx)
  1409.    return 0
  1410. end
  1411.  
  1412. return 1
  1413.  
  1414.  
  1415.  
  1416. /* ----  */
  1417. /* make headers and footers, host specific possibly */
  1418. make_head_foot:procedure expose aheaders. afooters. headlist. footlist. ,
  1419.         headers footers  nheads nfoots headers. footers.
  1420.  
  1421. foo=cvtails('headers.','b')
  1422. joe=arraysort('b')
  1423. crlf=' '
  1424. headers=' ' ; nheads=0 ; HDDONE=0
  1425. do mm=1 to b.0
  1426.     a1=b.mm
  1427.     a2=headers.a1
  1428.     if a2=" " then a2=0
  1429.     IF A2=0 then HDDONE=1
  1430.     if pos('.',a1)=0  then do
  1431.        if HDDONE=0 then  headers=headers||a2||crlf
  1432.     end  /* Do */
  1433.     else do             /* headers.hn */
  1434.        parse var a1 aval '.' ahost ; ahost=strip(ahost) ; aval=strip(aval)
  1435.        if strip(a2)=0 then do
  1436.              headstops.ahost=1
  1437.        end  /* Do */
  1438.        else do          /* not a stop */
  1439.          if aval=1 then  do
  1440.              nheads=nheads+1
  1441.               headlist.nheads=ahost
  1442.               aheaders.ahost=a2||crlf
  1443.              headstops.ahost=0
  1444.          end
  1445.          else do
  1446.            if headstops.ahost<>1 then
  1447.               aheaders.ahost=aheaders.ahost||a2||crlf
  1448.          end
  1449.        end              /* headstop */
  1450.     end                 /* .hn */
  1451. end
  1452. foo=cvtails('footers.','b')
  1453. joe=arraysort('b')
  1454. footers=' ' ; nfoots=0 ; FTDONE=0
  1455. do mm=1 to b.0
  1456.     a1=b.mm
  1457.     a2=footers.a1
  1458.     if a2=" " then a2=0
  1459.     IF A2=0 then FTDONE=1
  1460.     if pos('.',a1)=0  then do
  1461.        if FTDONE=0 then footers=footers||a2||crlf
  1462.     end  /* Do */
  1463.     else do             /* footers.hn */
  1464.        parse var a1 aval '.' ahost ; ahost=strip(ahost) ; aval=strip(aval)
  1465.        if strip(a2)=0 then do
  1466.              footstops.ahost=1
  1467.        end  /* Do */
  1468.        else do          /* not a stop */
  1469.          if aval=1 then  do
  1470.              nfoots=nfoots+1
  1471.               footlist.nfoots=ahost
  1472.               afooters.ahost=a2||crlf
  1473.              footstops.ahost=0
  1474.          end
  1475.          else do
  1476.            if footstops.ahost<>1 then
  1477.               afooters.ahost=afooters.ahost||a2||crlf
  1478.          end
  1479.        end              /* footstop */
  1480.     end                 /* .hn */
  1481. end
  1482.  
  1483. return 0
  1484.  
  1485.  
  1486. /*----------------------*/
  1487. save_em:
  1488. parse arg avar ;avar=strip(avar)
  1489.  
  1490. drop plist
  1491.  
  1492. avar0=strip(avar,'t','.')
  1493. avar=avar0||'.'
  1494. rr=cvtails(avar,'plist')
  1495. do r1=1 to rr
  1496.    atail=plist.r1
  1497.    interpret 't1='||avar||atail
  1498.    call value envadd||avar||atail,t1,'os2environment'
  1499. end
  1500.  
  1501. /* save the default (non hostname) version */
  1502.    if upper(symbol(avar0))="VAR" then do
  1503.       interpret 't1='||avar0
  1504.       call value envadd||avar0,t1,'os2environment'
  1505.    end
  1506.  
  1507. return 0
  1508.  
  1509.  
  1510. /* --- variable names of convert foo.bar.1 to foo.1.bar */
  1511. fix_me:procedure
  1512. parse arg a1
  1513.  
  1514. if a1=' '  then return a1
  1515. a1=strip(a1)
  1516. if abbrev(a1,';') then return a1
  1517.  
  1518. parse var a1  aname '=' avalue
  1519. if pos('.',aname)=0 then return a1
  1520.  
  1521. foo=translate(aname,' ','.')
  1522. if words(foo)<>3 then return a1
  1523.  
  1524. /* if here, array.x.y (3 elements) */
  1525. if datatype(word(foo,3))='NUM' & datatype(word(foo,2))<>'NUM' then do  /* rearrange */
  1526.    foo2=word(foo,1)||'.'||word(foo,3)||'.'||word(foo,2)||' = '||avalue
  1527.    return foo2
  1528. end  /* Do */
  1529. else do
  1530.    return a1
  1531. end  /* Do */
  1532.  
  1533.  
  1534.  
  1535.  
  1536.  
  1537.